package cn.itheima.action.system;

import cn.itheima.action.common.BaseAction;
import cn.itheima.domain.system.Menu;
import cn.itheima.service.system.MenuService;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created by millions on 2017/7/20.
 */
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class MenuAction extends BaseAction<Menu>{

    @Autowired
    private MenuService menuService;

    @Action(value = "menu_list",results = {@Result(type = "json")})
    public String list(){

        List<Menu> menus = menuService.findAll();
        // 存入值栈
        ActionContext.getContext().getValueStack().push(menus);

        return SUCCESS;
    }

    @Action(value = "menu_save",results = {@Result(type = "redirect",location = "pages/system/menu.html")})
    public String save(){

        menuService.save(model);
        return SUCCESS;
    }
}
